package io;

import java.io.*;
import java.nio.charset.StandardCharsets;

/*BufferedWriter和BufferedRead
* 8192长的char数组
*自动行刷新
*缓冲依靠BufferedWriter实现的
* 两个功能:自动行刷新,按行写字符串
*/
public class PwDemo {
    public static void main(String[] args) throws FileNotFoundException {
        /*
        PrintWriter pw = new PrintWriter("pw.txt");
        pw.println("童话说雨后会有彩虹");
        pw.println("却不曾说过");
        System.out.println("写出完毕");
        pw.close();
         */

        //文件流:低级流/节点流,作用:连接程序和文件的管道,负责将字节写入到文件中
        FileOutputStream fos = new FileOutputStream("pw2.txt");
        //转换流:高级流/字符流,作用:连接字节与字符流,负责将写出的字符转换为字节
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        //缓冲流:高级流/字符流,作用:内部默认维护8192长的char数组,总是以块写操作保证写出字符的效率
        BufferedWriter bw = new BufferedWriter(osw);
        //PrintWriter:高级流/字符流,作用:按行写出字符串(println),自动行刷新
        PrintWriter pw = new PrintWriter(bw);
        pw.println("童话说");
        pw.println("雨后会有彩虹");
        System.out.println("写出完毕");
        pw.close();
    }
}
